package GUI;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

import javax.swing.JComponent;

public class SkinnedButton extends JComponent implements MouseListener
{
	private static final long serialVersionUID = 9055373783136126139L;
	private String text = "";
	private ButtonSkin skin = null;
	private boolean pushed = false;
	private Vector<ActionListener> alisteners = new Vector<ActionListener>();
	
	public SkinnedButton(ButtonSkin skin, String text)
	{
		super();
		this.text = text;
		this.skin = skin;
		this.addMouseListener(this);
		
	}
	
	public void paintComponent(Graphics gg)
	{
		Graphics2D g = (Graphics2D)gg;
		if(skin != null)
			skin.drawSimpleButton(g, text, 0, 0, this.getWidth(), this.getHeight(), pushed);
	}
	
	public void addActionListener(ActionListener al)
	{
		alisteners.add(al);
	}
	
	public void removeActionListener(ActionListener al)
	{
		alisteners.remove(al);
	}
	
	private void notifyListeners()
	{
		ActionEvent ae = new ActionEvent(this, 0, text);
		for(int i = 0; i < alisteners.size(); ++i)
			alisteners.get(i).actionPerformed(ae);
	}

	@Override
	public void mouseClicked(MouseEvent arg0)
	{
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0)
	{
		pushed = true;
		repaint();
	}

	@Override
	public void mouseReleased(MouseEvent arg0)
	{
		pushed = false;
		repaint();
		notifyListeners();
	}
}
